//
//  TJTransferRecordController.m
//  Teleport
//
//  Created by xtjun on 2020/6/13.
//  Copyright © 2020 xtjun. All rights reserved.
//资产记录

#import "TJTransferRecordController.h"
#import "JXCategoryView.h"
#import "TJTransferRecordListController.h"


@interface TJTransferRecordController ()<JXCategoryViewDelegate, UIScrollViewDelegate>

@property (nonatomic, strong) JXCategoryTitleView *categoryView;
@property (strong, nonatomic) NSArray *types;

@property (strong, nonatomic) UIScrollView *mainView;

@end

@implementation TJTransferRecordController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.navigationBar.backgroundColor = UIColor_Hex(0x2C6CC7);
    self.navigationBar.lineView.hidden = YES;
    [self.navigationBar backBarButtonWhiteColor];
    self.navigationBar.titleTextColor = UIColor.whiteColor;
    self.navigationBar.title = @"资产记录".localizedString;
    
    
    _types = @[@"BTC", @"USDT"];
    
    self.categoryView.titles = _types;
    self.categoryView.titleFont = MediumFont(14);
    self.categoryView.titleColor = UIColor_Hex(0x333333);
    self.categoryView.titleSelectedColor = UIColor.tj_mainColor;
    self.categoryView.selectedAnimationEnabled = YES;
    self.categoryView.delegate = self;
    self.categoryView.titleLabelZoomEnabled = NO;
    self.categoryView.titleColorGradientEnabled = NO;
    self.categoryView.frame = CGRectMake(0, KNavBarHight, KScreenWidth, 40);
    self.categoryView.backgroundColor = UIColor.whiteColor;
    
    self.mainView = [UIScrollView tj_addToView:self.view];
    self.mainView.frame = CGRectMake(0, CGRectGetMaxY(self.categoryView.frame),KScreenWidth, KScreenHeight - KNavBarHight - CGRectGetHeight(self.categoryView.frame));
    self.mainView.pagingEnabled = YES;
    self.mainView.delegate = self;
    self.mainView.bounces = NO;
    self.mainView.contentSize = CGSizeMake(self.mainView.frame.size.width * _types.count, self.mainView.frame.size.height);
    self.mainView.showsHorizontalScrollIndicator = NO;
    self.mainView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.categoryView];
     //指示器样式
    JXCategoryIndicatorLineView *indicatorLineView = [[JXCategoryIndicatorLineView alloc] init];
    indicatorLineView.indicatorHeight = 2;
    indicatorLineView.indicatorColor = UIColor.tj_mainColor;
    self.categoryView.indicators = @[indicatorLineView];
    
    self.categoryView.defaultSelectedIndex = 0;
    
    [_types enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        TJTransferRecordListController *transferRecordListController = [[TJTransferRecordListController alloc] init];
        transferRecordListController.navigationBar.hidden = YES;
//        transferRecordListController.coinNo = @(idx + 1).stringValue;
        transferRecordListController.view.frame = CGRectMake(KScreenWidth * idx, 0, self.mainView.tj_width, self.mainView.tj_height);
        [self addChildViewController:transferRecordListController];
        [self.mainView addSubview:transferRecordListController.view];
    }];
 
    
}
#pragma mark ---------------JXCategoryViewDelegate------------------
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    [self.categoryView selectItemAtIndex:scrollView.contentOffset.x / KScreenWidth];
}
 
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    [self.mainView setContentOffset:CGPointMake(self.categoryView.tj_width * index, 0) animated:YES];
}


- (JXCategoryTitleView *)categoryView {
    if (_categoryView == nil) {
        _categoryView = [[JXCategoryTitleView alloc] init];
    }
    return _categoryView;
}


- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}


@end
